package com.sicheng.lc.杂题.栈;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/13 17:22
 */
public class 最值栈 {
    //https://leetcode.cn/problems/min-stack/
    static class MinStack {
        static int N = (int) (3 * 1e4);
        static int[] stack = new int[N];
        static int[] min = new int[N];
        static int top;

        public MinStack() {
            top = -1;
        }

        public void push(int val) {
            stack[top + 1] = val;
            if (top == -1)
                min[top + 1] = val;
            else
                min[top + 1] = Math.min(val, min[top]);
            top++;
        }

        public void pop() {
            top--;
        }

        public int top() {
            return stack[top];
        }

        public int getMin() {
            return min[top];
        }
    }
}
